﻿//Author:Michal Sporna
//License: https://operationsneakpeek.codeplex.com/license

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace World
{
    /// <summary>
    /// Handles saving and loading
    /// data
    /// THIS NEEDS TO BE IMPLEMENTED
    /// </summary>
    public static class StorageManager
    {
        #region properties

        #endregion

        #region METHOD

        #region WORD


        #region SAVE

        /// <summary>
        /// save word initial data
        /// </summary>
        public static void SaveWordInitialData()
        {
            try
            {

                //map=currentMap 
                //word set=true
                //letters!!
                //chosen word
                //map guess tries
                //num of letters found

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// save current word status
        /// </summary>
        public static void SaveWordStateForTheMap()
        {
            try
            {

                //map=currentMap 
                //letters
                //chosen word
                //map guess tries
                //num of letters found

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// save LettersPositioned flag
        /// for a specified map cell
        /// </summary>
        /// <param name="mapCellID"></param>
        public static void SaveLettersPositionedFlag(string mapCellID)
        {
            try
            {

                
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// save session info
        /// </summary>
        public static void SaveWorldInfo()
        {
            try
            {

                //world.Points
                //bombTries
                //energy
                //markers
                //battery
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// save stars for the map
        /// </summary>
        public static int  SavePointsAndStarsForTheMap()
        {
            //declare
           int stars=0;

            try
            {
                //convert points into stars and save
                if (Levels.LevelManager.CurrentMap.Points >= World.WorldManager.WorldConfig.PointsNeededFor1Star)
                {
                    //give 1 star
                    stars = 1;
                }

                if (Levels.LevelManager.CurrentMap.Points >= World.WorldManager.WorldConfig.PointsNeededFor2Stars)
                {
                    //give 2 stars
                    stars = 2;
                }

                if (Levels.LevelManager.CurrentMap.Points >= World.WorldManager.WorldConfig.PointsNeededFor3Stars)
                {
                    //give 3 stars
                    stars = 3;
                }

                //if (World.WorldManager.Points < World.WorldManager.WorldConfig.PointsNeededFor1Star)
                //{
                //    //give 0 stars
                //    stars = 0;
                //}

                
                return stars;
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return 0;
            }
        }

        /// <summary>
        /// save bonbm status for the map
        /// called after bomb found or defused
        /// </summary>
        public static void SaveBombStateForTheMap()
        {
            try
            {
                //defusing attempts
                //guessing attempts
                

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }


        /// <summary>
        /// save flags when points are awarded at the end of the map
        /// StarsAwardedForBombDefused
        /// StarsAwardedForAllLettersFound
        /// StarsAwardedForWordSolved
        /// </summary>
        public static void SaveAwardedStarsForTheMap()
        {
            try
            {



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        #endregion

        #region LOAD

        /// <summary>
        /// load word initial data
        /// </summary>
        /// <param name="mapID"></param>
        public static void LoadInitialWordData(string mapID)
        {
            try
            {
                //load chosen word from storage
                //load all information
                //find nodes that have letter and set HasLetter=true

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }

        }

        /// <summary>
        /// load word's details from storage
        /// where: levels.LevelManager load map
        /// </summary>
        public static void LoadWordState(string mapID)
        {
            try
            {
                //load chosen word from storage
                //load all information
                //find nodes that have letter and set HasLetter=true

                //letter:
                //set HasLetter to a node
                //set has letter
                //if (World.WorldManager.Nodes != null)
                //{
                //    for (int n = 0; n < World.WorldManager.Nodes.Count; n++)
                //    {
                //        if (World.WorldManager.Nodes[n].ID == newLetter.Pos[0] && World.WorldManager.Nodes[n].ID == newLetter.Pos[1])
                //        {
                //            World.WorldManager.Nodes[n].HasLetter = true;
                //            break;
                //        }
                //    }
                //}

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }

        }

        /// <summary>
        /// load bomb's details from storage
        /// bombs details for a current map
        /// </summary>
        public static void LoadBombState(string mapID)
        {
            try
            {
               //tries
                //guess pass tries
                //etc.

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }

        }

        /// <summary>
        /// load flags that tell us
        /// what was already awarded to user
        /// </summary>
        public static void LoadAwardedStarsStateForTheMap(string mapID)
        {
            try
            {



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }


        /// <summary>
        /// load stars 
        /// </summary>
        public static int LoadStarsForTheMap(string mapID)
        {
            try
            {
                



                return 0;

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return 0;
            }
        }

        /// <summary>
        /// load points
        /// </summary>
        public static int LoadPointsForTheMap(string mapID)
        {
            try
            {

                return 0;

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return 0;
            }
        }

        /// <summary>
        /// load letters positioned flag
        /// for specified map cell
        /// </summary>
        public static bool LoadLetterPositionedFlag(string mapCellID)
        {
            try
            {
                //return flag (false by default)
                return false;
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return false;
            }
        }

        /// <summary>
        /// load session info
        /// </summary>
        public static void LoadWorldInfo()
        {
            try
            {
                //#region load saved data

                //battery level

                //#region energy

                ////if data saved then load

                ////else load default value from map cell (only if map cell's energy is not -1[means that energy should not be taken from map cell])
                //if (Levels.LevelManager.CurrentMap.CurrentMapCell.Energy > -1)
                //{
                //    World.ScannerManager.Energy = Levels.LevelManager.CurrentMap.CurrentMapCell.Energy;
                //}
                ////else: without a change

                //#endregion

                #region markers

                //if no saved data


                //then:
                //load
                //default
                World.WorldManager.GreenMarkerCount = World.WorldManager.WorldConfig.DefautlGreenMarkerCount;
                World.WorldManager.OrangeMarkerCount = World.WorldManager.WorldConfig.DefautlOrangeMarkerCount;
                World.WorldManager.RedMarkerCount = World.WorldManager.WorldConfig.DefaultRedMarkerCount;

                #endregion

                //#region word&letters

                //#endregion

                //#endregion
             

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        #endregion

        #endregion


        #endregion

    }
}
